package Demo01;
import java.util.Arrays;
class Book implements Comparable<Book>{
    private String title;
    private double price;
    public Book(String title,double price){
        this.title = title;
        this.price = price;
    }
    public String toString(){
        return "【Book】图书名称" + this.title + "图书价格" + this.price + "\n";
    }
    @Override
    public int compareTo(Book o){
        if(this.price > o.price){
            return 1;
        }else if(this.price < o.price){
            return -1;
        }else{
            return 0;
        }
    }
}
public class Comparable16 {
    public static void main(String[] args) throws Exception {
        Book books[] = new Book[]{
                new Book("Java从入门到项目实战", 99.8),
                new Book("Python从入门到项目实战", 99.7),
                new Book("Go语言从入门到项目实战", 99.3)};
        Arrays.sort(books);
        System.out.println(Arrays.toString(books));
        }
    }
